package cz.acies.organizer.data.persist;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cz.acies.organizer.data.model.MModelRecord;
//import cz.acies.organizer.data.sync.google.SyncUserContext;

public class ContactRecord extends MModelRecord
{
	private static final long serialVersionUID = -5708402646594719773L;

	//private String id;
	private String matherId;

	//private String modulId = "LX_CONTACT";
	
	//private String folderId;
	private String firstName;
	private String middleName;
	private String lastName;
	private String title;
	private String sufix;
	private String company;
	private String jobTitle;
	private String nickName;
	private Date birthday;
	private String note;
	private PostalAddress homeAddress;
	private PostalAddress workAddress;
	private PhonesNumber telephone;
	private PhonesNumber mobile;
	private EmailAddress email;
	private String webPage;
	
	private String syncStatus;
	private String syncId;

	private List<EmailAddress> emailAddresses;
	private List<ImAddress> imAddresses;
	private List<PhonesNumber> phoneNumbers;
	
	//private SyncUserContext syncContext;
	
	public ContactRecord() {
		this(null, null);
	}

	public ContactRecord(String id) {
		this(id, null);
	}
	
	public ContactRecord(String id, Map<String, Object> data) {
		this.id = id;
		if (data != null) {
			this.data = data;
		}
		emailAddresses = new ArrayList<EmailAddress>();
		imAddresses = new ArrayList<ImAddress>();
		phoneNumbers = new ArrayList<PhonesNumber>();
	}

	// ----- -----------------------------------------------------------------

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getMatherId() {
		return matherId;
	}

	public void setMatherId(String matherId) {
		this.matherId = matherId;
	}

	public String getFolderId() {
		return folderId;
	}

	public void setFolderId(String folderId) {
		this.folderId = folderId;
	}

	public String getModulId() {
		return modulId;
	}
	
	public String getFirstName() {
		return (firstName != null) ? firstName : "";
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMiddleName() {
		return (middleName != null) ? middleName : "";
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public String getLastName() {
		return (lastName != null) ? lastName : "";
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getTitle() {
		return (title != null) ? title : "";
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCompany() {
		return (company != null) ? company : "";
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getJobTitle() {
		return (jobTitle != null) ? jobTitle : "";
	}

	public void setJobTitle(String jobTitle) {
		this.jobTitle = jobTitle;
	}
	
	public String getSufix() {
		return (sufix != null) ? sufix : "";
	}

	public void setSufix(String sufix) {
		this.sufix = sufix;
	}

	public Date getBirthday() {
		return birthday;
	}

	public boolean hasBirthday() {
		return birthday != null;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public PostalAddress getHomeAddress() {
		return homeAddress;
	}

	public void setHomeAddress(PostalAddress homeAddress) {
		this.homeAddress = homeAddress;
	}

	public PostalAddress getWorkAddress() {
		return workAddress;
	}

	public void setWorkAddress(PostalAddress workAddress) {
		this.workAddress = workAddress;
	}

	public PhonesNumber getTelephone() {
		return this.telephone;
	}

	public void setTelephone(PhonesNumber telephone) {
		this.telephone = telephone;
	}

	public String getWebPage() {
		return (webPage != null) ? webPage : "";
	}

	public void setWebPage(String webPage) {
		this.webPage = webPage;
	}

	public PhonesNumber getMobile() {
		return this.mobile;
	}

	public void setMobile(PhonesNumber mobile) {
		this.mobile = mobile;
	}

	public EmailAddress getEmail() {
		return this.email;
	}

	public void setEmail(EmailAddress email) {
		this.email = email;
	}

	public String getNote() {
		return (note != null) ? note : "";
	}

	public void setNote(String note) {
		this.note = note;
	}
	
	public String getNickName() {
		return (nickName != null) ? nickName : "";
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	// ----- ------------------------------------------------------------------
	
	public String getSyncId() {
		return (syncId != null) ? syncId : "";
	}

	public void setSyncId(String syncId) {
		this.syncId = syncId;
	}

	public String getSyncStatus() {
		return (syncStatus != null) ? syncStatus : "";
	}
	
	public void setSyncStatus(String syncStatus) {
		this.syncStatus = syncStatus;
	}

	// ----- ------------------------------------------------------------------
	/*
	public SyncUserContext getSyncContext() {
		return syncContext;
	}

	public void setSyncContext(SyncUserContext syncContext) {
		this.syncContext = syncContext;
	}
	*/
	// ----- ------------------------------------------------------------------
	
	public List<EmailAddress> getEmailAddresses() {
		return emailAddresses;
	}

	public void addEmailAddress(EmailAddress emailAddress) {
		this.emailAddresses.add(emailAddress);
	}

	public List<ImAddress> getImAddresses() {
		return imAddresses;
	}

	public void addImAddress(ImAddress imAddress) {
		this.imAddresses.add(imAddress);
	}

	public List<PhonesNumber> getPhoneNumbers() {
		return phoneNumbers;
	}

	public void addPhoneNumber(PhonesNumber phoneNumber) {
		this.phoneNumbers.add(phoneNumber);
	}

	// ----- -----------------------------------------------------------------
	
	public void mapToData(Map<String, Object> map) {
		if (map.containsKey("FOLDER_ID"))
			folderId = (String) map.get("FOLDER_ID");
		if (map.containsKey("FIRST_NAME"))
			firstName = (String) map.get("FIRST_NAME");
		if (map.containsKey("MIDDLE_NAME"))
			middleName = (String) map.get("MIDDLE_NAME");
		if (map.containsKey("LAST_NAME"))
			lastName = (String) map.get("LAST_NAME");
		
		if (map.containsKey("TITLE"))
			title = (String) map.get("TITLE");
		if (map.containsKey("SUFIX"))
			sufix = (String) map.get("SUFIX");
		if (map.containsKey("COMPANY"))
			company = (String) map.get("COMPANY");
		if (map.containsKey("JOB_TITLE"))
			jobTitle = (String) map.get("JOB_TITLE");
		if (map.containsKey("NICK_NAME"))
			nickName = (String) map.get("NICK_NAME");
		//birthday = (Date) map.get("");
		if (map.containsKey("NOTE"))
			note = (String) map.get("NOTE");
		if (map.containsKey("HOME_ADDRESS"))
			homeAddress = PostalAddress.parse((String) map.get("HOME_ADDRESS"));
		if (map.containsKey("WORK_ADDRESS"))
			workAddress = PostalAddress.parse((String) map.get("WORK_ADDRESS"));
		
		if (map.containsKey("HOME_PHONE"))
			telephone = new PhonesNumber((String) map.get("HOME_PHONE")); 
		//telephone = new PhonesNumber((String) map.get("WORK_PHONE"));
		if (map.containsKey("MOBILE"))
			mobile = new PhonesNumber((String) map.get("MOBILE"));
		if (map.containsKey(""))
			email = new EmailAddress((String) map.get("EMAIL"));
		if (map.containsKey("WEB_PAGE"))
			webPage = (String) map.get("WEB_PAGE");
			
		/*
		EDIT_DATE=2012-07-21 09:40:04.0, 
		HOME_ADDRESS=;;Sídliště 1425;Lysá nad Labem;;28922;;, 
		EDITOR_ID=W_ADMIN, 
		WRITER_ID=W_ADMIN, 
		SOURCE_TYPE=FILE_VCARD, 
		FNBL_SYNC_STATUS=U, 
		G_SYNC_STATUS=U, 
		FNBL_SYNC_ID=null, 
		WRITE_DATE=2011-04-23 22:45:55.0, 
		SOURCE_FILE=Adam, Jirka.vcf,
		*/ 
	}

}
